//package com.ugoodtech.mdcc.client.service.impl;
//
//import com.mysema.query.BooleanBuilder;
//import com.ugoodtech.mdcc.client.dto.JsonResponse;
//import com.ugoodtech.mdcc.client.service.CustomerSatisfactionReportService;
//import com.ugoodtech.mdcc.core.domain.*;
//import com.ugoodtech.mdcc.core.repository.StationRepository;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//@Service
//public class CustomerSatisfactionReportServiceImpl implements CustomerSatisfactionReportService {
//
//
//    @Autowired
//    private StationRepository stationRepository;
//
//
//    /**
//     * 创建客户满意度报告
//     *
//     * @param customerSatisfactionReport
//     * @param user
//     * @param reportId
//     * @return
//     */
//    @Override
//    public JsonResponse createCustomerSatisfactionReport(CustomerSatisfactionReport customerSatisfactionReport, User user, Long reportId) {
//        if (customerSatisfactionReport == null) {
//            return JsonResponse.errorResponseWithError("405", "CustomerSatisfactionReport参数错误");
//        }
//
//        if (!user.getUserType().equals(UserType.customer)) {
//            return JsonResponse.errorResponseWithError("抱歉", "您不是客户,无法填写满意度调查问卷");
//        }
//        try {
//            QStation qStation = QStation.station;
//            BooleanBuilder builder = new BooleanBuilder();
//            builder.and(qStation.user.id.eq(user.getId()));
//            Station station = stationRepository.findOne(builder);
//            customerSatisfactionReport.setStation(station);
//            if (reportId != null && reportId != 0) {
//                StationServiceReport stationServiceReport = stationServiceReportRepository.findOne(reportId);
//                if (stationServiceReport != null) {
//                    customerSatisfactionReport.setReport(stationServiceReport);
//                }
//            }
//            customerSatisfactionReport.setTotalScore(getTotalScore(customerSatisfactionReport));
//            customerSatisfactionReportRepository.save(customerSatisfactionReport);
//            return JsonResponse.successResponse();
//        } catch (Exception e) {
//            return JsonResponse.errorResponseWithError("500", "执行save错误");
//        }
//    }
//
//
//    private String getTotalScore(CustomerSatisfactionReport customerSatisfactionReport) {
//        Integer score1 = returnInteger(customerSatisfactionReport.getBeforeTheService());
//        Integer score2 = returnInteger(customerSatisfactionReport.getIsOnTime());
//        Integer score3 = returnInteger(customerSatisfactionReport.getIsUniform());
//        Integer score4 = returnInteger(customerSatisfactionReport.getSolution());
//        Integer score5 = returnInteger(customerSatisfactionReport.getWorkAttitude());
//        Integer score6 = returnInteger(customerSatisfactionReport.getIsExpect());
//        Integer score7 = returnInteger(customerSatisfactionReport.getScore());
//        Integer totalScore = (score1 + score2 + score3 + score4 + score5 + score6 + score7) / 7;
//        return String.valueOf(totalScore);
//    }
//
//    private Integer returnInteger(String string) {
//        string = string.replace("%", "");
//        return Integer.valueOf(string);
//    }
//
//
//}
